package models;

import java.sql.PreparedStatement;
import play.*;
import play.db.jpa.*;

import javax.persistence.*;

import java.util.*;
import play.data.validation.*;

@Entity
@Table(name = "categories")
public class Category extends Model {

    @Required
    public String name;
    @OneToMany
    public List<Article> article;

    public Category(String name) {

        this.name = name;
    }

    @Override
    public String toString() {
        return this.name;
    }

    public int getNbNews() {
        int number = (int) Article.count("category_id = ?", this.id);
        return number;
    }
}
